package com.ynkbny.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ynkbny.base.PageResult;
import com.ynkbny.domain.DeviceAttribute;
import com.ynkbny.domain.pojo.DeviceAttributeListVO;
import com.ynkbny.domain.pojo.DeviceAttributePaginReqVO;
import com.ynkbny.mapper.DeviceAttributeMapper;
import com.ynkbny.service.DeviceAttributeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;


/**
 * 设备的属性快照-表服务实现类
 *
 * @author : juzipi123
 * @date : 2023-7-26
 */
@Slf4j
@Service
public class DeviceAttributeServiceImpl extends ServiceImpl<DeviceAttributeMapper, DeviceAttribute> implements DeviceAttributeService {

    @Resource
    DeviceAttributeMapper mapper;

    /**
     * 根据 项目id 删除
     *
     * @author : juzipi123
     * @param projId 项目id
     */
    @Override
    public void delByProjId(Long projId) {
        mapper.delByProjId(projId);
    }

    /**
     * 删除所有数据
     *
     * @author : juzipi123
     */
    @Override
    public void del() {
        mapper.del();
    }

    /**
     * 分页查询
     *
     * @author : juzipi123
     * @param vo 筛选条件
     * @return 查询结果
     */
    @Override
    public PageResult<DeviceAttribute> paginQuery(DeviceAttributePaginReqVO vo) {
        log.info("入参：{}",vo);

        //1. 构建动态查询条件
        LambdaQueryWrapper<DeviceAttribute> queryWrapper = new LambdaQueryWrapper<>();
        if (ObjectUtils.isNotEmpty(vo.getProjectId())) {
            queryWrapper.eq(DeviceAttribute::getProjectId, vo.getProjectId());
        }
        if (ObjectUtils.isNotEmpty(vo.getStatus())) {
            queryWrapper.eq(DeviceAttribute::getStatus, vo.getStatus());
        }
        if (ObjectUtils.isNotEmpty(vo.getParamName())) {
            queryWrapper.like(DeviceAttribute::getParamName, vo.getParamName());
        }
        if (ObjectUtils.isNotEmpty(vo.getFlag())) {
            queryWrapper.eq(DeviceAttribute::getFlag, vo.getFlag());
        }

        Page<DeviceAttribute> page = new Page<>(vo.getCurrentPage(), vo.getPageSize());

        //2. 返回结果
        PageResult<DeviceAttribute> pageResult = new PageResult<>(this.page(page, queryWrapper));
        log.info("方法返回：{}",pageResult);
        return pageResult;
    }

    /**
     * 查询 设备的属性快照 列表
     *
     * @author : juzipi123
     * @param vo 筛选条件
     * @return 结果
     */
    @Override
    public List<DeviceAttribute> getList(DeviceAttributeListVO vo) {
        log.info("入参：{}",vo);

        //1. 构建动态查询条件
        LambdaQueryWrapper<DeviceAttribute> queryWrapper = new LambdaQueryWrapper<>();
        if (ObjectUtils.isNotEmpty(vo.getProjectId())) {
            queryWrapper.eq(DeviceAttribute::getProjectId, vo.getProjectId());
        }
        if (ObjectUtils.isNotEmpty(vo.getStatus())) {
            queryWrapper.eq(DeviceAttribute::getStatus, vo.getStatus());
        }
        if (ObjectUtils.isNotEmpty(vo.getParamName())) {
            queryWrapper.like(DeviceAttribute::getParamName, vo.getParamName());
        }
        if (ObjectUtils.isNotEmpty(vo.getFlag())) {
            queryWrapper.eq(DeviceAttribute::getFlag, vo.getFlag());
        }

        List<DeviceAttribute> list = this.list(queryWrapper);

        log.info("方法返回：{}",list);
        return list;
    }
}